import config from "../util/config";
import {h} from "vue";
import {formatDateTime} from "../util/utils";
import store from "../store";

export class UserLoginParam {
    username?: string;
    pwd?: string;
    captcha?: string;
    captchaToken?: string;
}

export class UserLoginVO {
    token?: string;
    captchaToken?: string;
    captchaImage?: string;
}

export class AddUserParam {
    username?: string;
    pwd?: string;
    repeatPwd?: string;
    auth?: number;
}

export class UpdateUserParam {
    id?: bigint;
    username?: string;
    auth?: number;
}

export class PageQueryUserParam {
    username?: string;
    auth?: number
}

export class ApiUserVO extends UpdateUserParam{
    enabled?: boolean;
    createTime?: number;
    updateTime?: number;
    lastLoginTime?: number;
}

const userAuthMap: Map<number, string> = store().enumMapStore["UserAuth"];

export const basicColumns = [
    {
        title: "用户名",
        key: "username",
        ellipsis: {
            tooltip: true
        }
    },
    {
        title: "权限",
        key: "auth",
        render: (rowData: JobUserVO) => {
            return userAuthMap.get(rowData.auth as number);
        }
    },
    {
        title: "创建时间",
        key: "createTime",
        width: config.dateTimeColumnWidth,
        render: (rowData: JobUserVO) => {
            return h("span", formatDateTime(rowData.createTime));
        }
    },
    {
        title: "更新时间",
        key: "updateTime",
        width: config.dateTimeColumnWidth,
        render: (rowData: JobUserVO) => {
            return h("span", formatDateTime(rowData.updateTime));
        }
    },
    {
        title: "上次尝试登录时间",
        key: "lastLoginTime",
        width: config.dateTimeColumnWidth,
        render: (rowData: JobUserVO) => {
            return h("span", formatDateTime(rowData.lastLoginTime));
        }
    }
];

export const addRules = {
    username: {
        required: true,
        message: "请输入用户名",
        trigger: ["blur"]
    },
    pwd: {
        required: true,
        message: "请输入密码",
        trigger: ["blur"]
    },
    repeatPwd: [{
        required: true,
        message: "请再次输入密码",
        trigger: ["blur"]
    }]
};

export const updateRules = {
    username: {
        required: true,
        message: "请输入用户名",
        trigger: ["blur"]
    }
};
